package com.zhouker.workback.util;

import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;


/**
 * @author ASUS
 */
//@PropertySource("classpath:application.properties")
public class DButil {
	//	@Value("${spring.datasource.url}")
	private static String url;
	//	@Value("${spring.datasource.username}")
	private static String user;
	//	@Value("${spring.datasource.password}")
	private static String password;
	//	@Value("${spring.datasource.driver-class-name}")
	private static String driver;
	
	/*
	static {
		try{
			System.out.printf("%s\n%s\n%s\n",url,user,password);
			Class.forName(driver);
		}catch (Exception e){
			e.printStackTrace();
		}
	}
	 */
	static {
		try {
			//读取配置文件
			InputStream in = new FileInputStream("");
			Properties properties = new Properties();
			//加载配置文件
			properties.load(in);
			//获取配置文件中的数据
			String driver = properties.getProperty("driver");
			url = properties.getProperty("url");
			user = properties.getProperty("user");
			password = properties.getProperty("password");
			//加载数据库链接驱动
			Class.forName(driver);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 获取一个数据库链接
	 */
	public static Connection getConnection() throws SQLException {
		return DriverManager.getConnection(url, user, password);
	}
}